"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    }
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var sprite = /** @class */ (function () {
    function sprite() {
    }
    sprite.prototype.setup = function (p) {
    };
    sprite.prototype.draw = function (p) {
    };
    return sprite;
}());
var xyz_sprite = /** @class */ (function (_super) {
    __extends(xyz_sprite, _super);
    function xyz_sprite() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    xyz_sprite.prototype.draw = function (p) {
        var a = 50;
        var b = 50 / 50;
        var o = a * 0.5;
        p.push();
        p.translate(o, 0, 0);
        p.ambientMaterial(255, 0, 0);
        p.box(a, b, b);
        p.pop();
        p.push();
        p.translate(0, o, 0);
        p.ambientMaterial(0, 255, 0);
        p.box(b, a, b);
        p.pop();
        p.push();
        p.translate(0, 0, o);
        p.ambientMaterial(0, 0, 255);
        p.box(b, b, a);
        p.pop();
    };
    return xyz_sprite;
}(sprite));
var ground_sprite = /** @class */ (function (_super) {
    __extends(ground_sprite, _super);
    function ground_sprite() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    ground_sprite.prototype.setup = function (p) {
        this._img = p.createGraphics(50, 50);
        this._img.background(200);
        this._img.stroke(153);
        this._img.line(0, 25, 50, 25);
        this._img.line(25, 0, 25, 50);
        this._img.line(0, 0, 50, 0);
        this._img.line(50, 0, 50, 50);
        this._img.line(50, 50, 50, 0);
        this._img.line(0, 0, 0, 50);
        this._x = 0;
    };
    ground_sprite.prototype.draw = function (p) {
        for (var i = -9; i < 10; i++) {
            for (var j = -9; j < 10; j++) {
                p.push();
                p.translate(i * 10, j * 10, 0);
                p.texture(this._img);
                p.plane(10);
                p.pop();
            }
        }
    };
    return ground_sprite;
}(sprite));
var wallbox = /** @class */ (function (_super) {
    __extends(wallbox, _super);
    function wallbox(data) {
        var _this = this;
        _this._data = data;
        return _this;
    }
    wallbox.prototype.draw = function (p) {
        this._data.map(function (d) {
            p.push();
            if (d.Type == 2) {
                p.translate(d.X, d.Y, 2);
                p.ambientMaterial(255, 255, 255);
                p.box(1, 1, 4);
                //p.translate(0-d.X, 0-d.Y, -2);
            }
            else if (d.Type == 1) {
                p.translate(d.X, d.Y, 1.5);
                p.ambientMaterial(255, 153, 0);
                p.box(1, 1, 3);
                //p.translate(0-d.X, 0-d.Y, -1.5);
            }
            p.pop();
        });
    };
    return wallbox;
}(sprite));
var p3d = /** @class */ (function () {
    function p3d(doc) {
        this._doc = doc;
        this._spriteArray = [];
    }
    p3d.prototype.add = function (s) {
        this._spriteArray.push(s);
    };
    p3d.prototype.setup = function (that) {
        that._p.pixelDensity(1);
        var myCanvas = that._p.createCanvas(that._doc.clientWidth, that._doc.clientHeight, that._p.WEBGL);
        that._p.setAttributes('antialias', true);
        that._render = that._p._renderer;
        that._easycam = new Dw.EasyCam(that._render, { distance: 300 });
        that._doc.appendChild(that._p.canvas);
        that._spriteArray.map(function (x) { return x.setup(that._p); });
    };
    p3d.prototype.windowResized = function (that) {
        that._p.resizeCanvas(that._doc.clientWidth, that._doc.clientHeight);
        that._easycam.setViewport([0, 0, that._doc.clientWidth, that._doc.clientHeight]);
    };
    p3d.prototype.draw = function (that) {
        that._p.perspective(60 * 3.14 / 180, that._doc.clientWidth / that._doc.clientHeight, 1, 5000);
        that._p.background(255);
        that._p.noStroke();
        // lights
        that._p.ambientLight(100);
        that._p.pointLight(255, 255, 255, 100, 0, 100);
        // objects
        that._spriteArray.map(function (x) { return x.draw(that._p); });
    };
    p3d.prototype.init = function () {
        var that = this;
        var sketch = function (p) {
            p.setup =
                function () {
                    that.setup(that);
                };
            p.draw =
                function () {
                    that.draw(that);
                };
            p.windowResized = function () {
                that.windowResized(that);
            };
        };
        this._p = new p5(sketch);
    };
    return p3d;
}());
